{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Jupyter Notebook for Checking Python Package Requirements"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from distutils.version import LooseVersion as Version\n",
    "\n",
    "\n",
    "def get_packages(pkgs):\n",
    "    versions = []\n",
    "    for p in packages:\n",
    "        try:\n",
    "            imported = __import__(p)\n",
    "            try:\n",
    "                versions.append(imported.__version__)\n",
    "            except AttributeError:\n",
    "                try:\n",
    "                    versions.append(imported.version)\n",
    "                except AttributeError:\n",
    "                    try:\n",
    "                        versions.append(imported.version_info)\n",
    "                    except AttributeError:\n",
    "                        versions.append('0.0')\n",
    "        except ImportError:\n",
    "            print('[FAIL]: %s is not installed' % p)\n",
    "    return versions\n",
    "                    \n",
    "packages = ['numpy', 'scipy', 'matplotlib', 'sklearn', 'pandas']\n",
    "suggested_v = ['1.10', '0.17', '1.5.1', '0.17.1', '0.17.1']\n",
    "versions = get_packages(packages)\n",
    "\n",
    "for p, v, s in zip(packages, versions, suggested_v):\n",
    "    if Version(v) < Version(s):\n",
    "        print('[FAIL] %s %s, please upgrade to >= %s' % (p, v, s))\n",
    "    else:\n",
    "        print('[OK] %s %s' % (p, v))"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
